// echo
def HasChar 0xfff0
def GetChar 0xfff1
def PutChar 0xffff

def pt	0x8000
def arg0 0x8004
def ret0 0x8006
def pc0	0x8008
def pc0l 0x8008
def pc0h 0x8009

dat d	1 0x1 0b01 'A'
str m	"Hello\n"

start:
	ldi l(m)
	stm pt
	ldi h(m)
	stm pt+1
	
show:
	ldp pt
	jz getchar
	stm PutChar
	ldm pt
	addi 1
	stm pt
	jmp show

getchar:
    ldm HasChar
    jz  getchar
    ldm GetChar

	stm arg0

// jsr l2h
	stpc pc0
	ldi 0
	addi 0
	ldm pc0l	
	addi 2+2+3+2+3+3+2+3+3
	stm pc0l
	ldm pc0h
	addi 0
	stm pc0h
	jmp l2h

	ldm ret0

putchar:
    stm PutChar
    jmp getchar


l2h:
	ldi 0
	addi 0
	ldm arg0
	subi 0x61
	jc l2hret

	ldi 0
	addi 0
	ldm arg0
	subi 0x7a
	jnc l2hret

	ldi 0
	addi 0
	ldm arg0
	subi 0x20
	stm arg0

l2hret:
	ldm arg0
	stm ret0
	
	ldpc pc0
	
